#ifndef _TK_PID_H_
#define _TK_PID_H_
/*---------------------------------------------------------------------------------------------------------*/
//输出功率限幅 以实际加热功率定
#define MAXOUTVALUE 2100
#define MINOUTVALUE 0
/*---------------------------------------------------------------------------------------------------------*/
#define PID_KP 10
#define PID_KI 8
#define PID_KD 0.1
// PID控制器结构体定义
typedef struct {
    unsigned int set_value;         // 目标温度值 (0.1°C)
    unsigned int actual_value;      // 当前温度值 (0.1°C)
    float err;                      // 当前误差
    float err_next;                 // 上一次误差
    float err_last;                 // 上两次误差
    float kp;                       // 比例系数
    float ki;                       // 积分系数
    float kd;                       // 微分系数
    unsigned int out;               // 加热功率输出 (MINOUTVALUE-MAXOUTVALUE)
    unsigned char  pumpDuty;        // 水泵输出占空比 (0-100)
} PID_HandleTypeDef;
/*---------------------------------------------------------------------------------------------------------*/
extern PID_HandleTypeDef TargetPID;
/*---------------------------------------------------------------------------------------------------------*/
//水泵温度拟合曲线结构体定义
typedef struct {
    signed int a;
    signed int b;
    signed int c;
    unsigned char pumpDuty;
    unsigned int tempDiff;
} PumpCoeff;
/*---------------------------------------------------------------------------------------------------------*/
extern void PID_Init(PID_HandleTypeDef *hpid, unsigned int u16_PresentValue, unsigned int u16_TargetValue);
extern unsigned int PID_Calculate(PID_HandleTypeDef *hpid, unsigned int u16_PresentValue);
/*---------------------------------------------------------------------------------------------------------*/
#endif 
